package com.token.sql;
import java.sql.SQLException;

/**
 *
 * @author chenjianxiong  2020/4/21
 */
public class TableBeanPrepareSql extends PrepareSql {
    private final AbstractTableBean bean;
    public TableBeanPrepareSql(AbstractTableBean bean) {
        super(bean.integrateSql);
        this.bean = bean;
    }

    /**
     * 预编 Select
     * @param strWhere 条件语名 如 aa=? and bb=?
     * @throws SQLException 抛出错误
     */
    public void setSelectPrepare(String strWhere) throws SQLException {
        StringBuffer sql = new StringBuffer(50);
        sql.append(bean.selectCode()).append(" where ").append(strWhere);
        super.setPrepare(sql);

    }


    /**
     * 预编 update
     * @param strSetFieldName set的字段，如：a=?,b=?
     * @param strWhere 条件语句：a=? and b=?
     * @throws SQLException
     */
    public void setUpdatePrepare(String strSetFieldName,String strWhere) throws SQLException {
        StringBuffer sql = new StringBuffer(50);
        sql.append("update ").append(bean.getTableName()).append(" set ").append(strSetFieldName)
                .append(" where ").append(strWhere);
        super.setPrepare(sql);

    }

    /**
     * 预编 delete
     * @param strWhere 条件：a=? and b=?
     * @throws SQLException  抛出错误
     */
    public void setDeletePrepare(String strWhere) throws SQLException {
        StringBuffer sql = new StringBuffer(50);
        sql.append("delete from ").append(bean.getTableName())
                .append(" where ").append(strWhere);
        super.setPrepare(sql);

    }
}
